package com.bdqn.pojo;

import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Past;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 系统用户实体类
 */
public class SysUser implements Serializable {

    private static final long serialVersionUID = 42L;

    private String roleName;
    private Long id;
    private String account;
    private String realName;
    private String password;
    private Long sex;
    @Past(message = "生日必须是一个过去的时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    private String phone;
    private String address;
    private Long roleId;
    private String idPicPath;
    private String workPicPath;
    private Long createdUserId;
    private String createdTime;
    private Long updatedUserId;
    private String updatedTime;
    private Long age;

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleIdName) {
        this.roleName = roleIdName;
    }

    public Long getAge() {
        Calendar calendar = Calendar.getInstance();
        // calendar.setTime(new SimpleDateFormat("yyyy").parse(this.birthday));
        calendar.setTime(this.birthday);
        return (long) (Calendar.getInstance().get(Calendar.YEAR) - calendar.get(Calendar.YEAR));
    }

    public void setAge(Long age) {
        this.age = age;
    }

    /**
     * 显示其他表字段
     */
    private String userRoleName;

    public String getUserRoleName() {
        return userRoleName;
    }

    public void setUserRoleName(String userRoleName) {
        this.userRoleName = userRoleName;
    }

    /**
     * 用户和角色一对一关系 将系统角色类型作为SysUser的属性
     */
    private SysRole sysRole;

    public SysRole getSysRole() {
        return sysRole;
    }

    public void setSysRole(SysRole sysRole) {
        this.sysRole = sysRole;
    }

    /**
     * 用户和收获地址一对多关系 用集合关联多的一方
     */
    private List<Address> addressList;

    public List<Address> getAddressList() {
        return addressList;
    }

    public void setAddressList(List<Address> addressList) {
        this.addressList = addressList;
    }



    @Override
    public String toString() {
        return "SysUser{" +
                "id=" + id +
                ", account='" + account + '\'' +
                ", realName='" + realName + '\'' +
                ", password='" + password + '\'' +
                ", sex=" + sex +
                ", birthday='" + birthday + '\'' +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                ", roleId=" + roleId +
                ", userRoleName='" + userRoleName + '\'' +
                ", idPicPath='" + idPicPath + '\'' +
                ", workPicPath='" + workPicPath + '\'' +
                ", createdUserId=" + createdUserId +
                ", createdTime='" + createdTime + '\'' +
                ", updatedUserId=" + updatedUserId +
                ", updatedTime='" + updatedTime + '\'' +
                ", sysRole=" + sysRole +
                '}';
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getSex() {
        return sex;
    }

    public void setSex(Long sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public String getIdPicPath() {
        return idPicPath;
    }

    public void setIdPicPath(String idPicPath) {
        this.idPicPath = idPicPath;
    }

    public String getWorkPicPath() {
        return workPicPath;
    }

    public void setWorkPicPath(String workPicPath) {
        this.workPicPath = workPicPath;
    }

    public Long getCreatedUserId() {
        return createdUserId;
    }

    public void setCreatedUserId(Long createdUserId) {
        this.createdUserId = createdUserId;
    }

    public String getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(String createdTime) {
        this.createdTime = createdTime;
    }

    public Long getUpdatedUserId() {
        return updatedUserId;
    }

    public void setUpdatedUserId(Long updatedUserId) {
        this.updatedUserId = updatedUserId;
    }

    public String getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(String updatedTime) {
        this.updatedTime = updatedTime;
    }

}
